home *** CD-ROM | disk | FTP | other *** search
- package com.commerceone.util.collection;
-
- import com.commerceone.util.contract.Contract;
- import java.beans.PropertyChangeEvent;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Properties;
- import java.util.Vector;
-
- public class PropertyDiff {
- public static Enumeration getDifference(Object source, Properties oldProps, Properties newProps) {
- Vector changes = new Vector();
- Enumeration oldPropNames = oldProps.propertyNames();
-
- while(oldPropNames.hasMoreElements()) {
- String oldName = oldPropNames.nextElement().toString();
- Object oldValue = ((Hashtable)oldProps).get(oldName);
- Contract.require(oldValue != null);
- Object newValue = ((Hashtable)newProps).get(oldName);
- if (newValue == null) {
- PropertyChangeEvent pce = new PropertyChangeEvent(source, oldName, oldValue, (Object)null);
- changes.addElement(pce);
- } else if (!oldValue.equals(newValue)) {
- PropertyChangeEvent pce = new PropertyChangeEvent(source, oldName, oldValue, newValue);
- changes.addElement(pce);
- }
- }
-
- oldPropNames = newProps.propertyNames();
-
- while(oldPropNames.hasMoreElements()) {
- String newName = oldPropNames.nextElement().toString();
- Object newValue = ((Hashtable)newProps).get(newName);
- Contract.require(newValue != null);
- Object oldValue = ((Hashtable)oldProps).get(newName);
- if (oldValue == null) {
- PropertyChangeEvent pce = new PropertyChangeEvent(source, newName, (Object)null, newValue);
- changes.addElement(pce);
- }
- }
-
- return changes.elements();
- }
- }
-